cmake_minimum_required(VERSION 3.4)
set(PROJ_NAME case15)
project(${PROJ_NAME})

set(LIB_NAME ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/MyLib.lib)

add_custom_command(OUTPUT ${LIB_NAME}
    COMMAND cl /c $<$<CONFIG:Release>:/MD>$<$<CONFIG:Debug>:/MDd> ${CMAKE_CURRENT_SOURCE_DIR}/func1.cpp /Fo${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/func1.obj
    COMMAND link /lib /out:${LIB_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/func1.obj
    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/func1.cpp
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    COMMENT "Create custom library"
    VERBATIM
    )

add_custom_target(combinedLib
    DEPENDS
    ${LIB_NAME}
    )

add_executable(${PROJ_NAME}
    main.cpp
    )

target_compile_options(${PROJ_NAME} PUBLIC
    $<$<CONFIG:Release>:/MD>
    $<$<CONFIG:Debug>:/MDd>
    )

add_library(mylib STATIC IMPORTED)
set_target_properties(mylib PROPERTIES IMPORTED_LOCATION ${LIB_NAME})
add_dependencies(mylib combinedLib)

target_link_libraries(${PROJ_NAME}
    mylib
    )
